cmake_minimum_required (VERSION 3.5 FATAL_ERROR)

cmake_policy (SET CMP0054 NEW)

option (YOCTO "Use YOCTO depedencies system" ON)
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED ON)

set (
    CMAKE_CXX_FLAGS
    "${CMAKE_CXX_FLAGS} \
    -Werror \
    -Wtype-limits \
    -Wnull-dereference \
"
)

project (phytium-ipmi-oem CXX)

add_definitions (-DBOOST_ERROR_CODE_HEADER_ONLY)
add_definitions (-DBOOST_SYSTEM_NO_DEPRECATED)
add_definitions (-DBOOST_ALL_NO_LIB)
add_definitions (-DBOOST_NO_RTTI)
add_definitions (-DBOOST_NO_TYPEID)
add_definitions (-DBOOST_ASIO_DISABLE_THREADS)
add_definitions (-DBOOST_COROUTINES_NO_DEPRECATION_WARNING)
add_definitions (-Wno-psabi)

if (YOCTO)
    find_package (PkgConfig REQUIRED)
    pkg_check_modules (LOGGING phosphor-logging REQUIRED)
    include_directories (SYSTEM ${LOGGING_INCLUDE_DIRS})
    link_directories (${LOGGING_LIBRARY_DIRS})

    pkg_check_modules (LIBIPMID libipmid REQUIRED)
    include_directories (SYSTEM ${LIBIPMID_INCLUDE_DIRS})
    link_directories (${LIBIPMID_LIBRARY_DIRS})

endif ()

include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)

add_library (phytiumoemcmds
             SHARED src/devicehandler.cpp src/hostmonitor.cpp
                    src/cperhandler.cpp src/boardadaptive.cpp
                    src/tcmhandler.cpp)
set_target_properties (phytiumoemcmds PROPERTIES VERSION "0.1.0")
set_target_properties (phytiumoemcmds PROPERTIES SOVERSION "0")
target_link_libraries (phytiumoemcmds stdc++fs)
target_link_libraries (phytiumoemcmds ipmid)
target_link_libraries (phytiumoemcmds sdbusplus)
target_link_libraries (phytiumoemcmds ipmiblob)
target_link_libraries (phytiumoemcmds phosphor_logging)
target_link_libraries (phytiumoemcmds phytium-cper-parse)
target_link_libraries (phytiumoemcmds fmt)
target_link_libraries (phytiumoemcmds systemd)

option (TPCM_ENABLE "Use Phytium tpcm device" OFF)

if (TPCM_ENABLE)
    target_compile_definitions (phytiumoemcmds PRIVATE TPCM_ENABLE)
    target_link_libraries (phytiumoemcmds tsbapi)
endif()

install (TARGETS phytiumoemcmds DESTINATION lib/ipmid-providers)
